package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-17 18:16
 */
public class Solution_0459 {
    /**
     * 重复字符串
     * 判读一个字符串是否可以由它的子字符串构成
     *
     * @param s
     * @return
     */
    public boolean repeatedSubstringPattern(String s) {
        /**
         * s的一半是最大的子字符串
         */
        String temp = null;
        String after = null;
        for (int i = 0; i < s.length() / 2; i++) {
            temp = s.substring(0, i + 1);
            after = this.createNewString(temp, s.length());
            if (after.equals(s))return true;
        }
        return false;
    }

    /**
     * 如果能由子串构成，父串长度必是字串长度n倍
     *
     * @param child
     * @param size
     * @return
     */
    public String createNewString(String child, int size) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < size / child.length(); i++) {
            stringBuilder.append(child);
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        String s = new String("1111");
        Solution_0459 solution_0459 = new Solution_0459();
        boolean b = solution_0459.repeatedSubstringPattern(s);
        System.out.println(b);
    }
}
